<?php include "../public/header.php";?>
<?php include "../public/header_index.php";?>
<?php include "../public/header_show.php";?>
<body id="showPage">
<div id="showBox">
    <div class="page-title">
        <div class="page-title-con">
            <span>详情</span>
            <div class="page-title-opt-list">
                <?php include "../public_flow/flow_show_optbut.php";?>
                <button class="layui-btn layui-btn-sm btn-light marginr5 opt">
                    操作<i class="layui-icon layui-icon-down layui-font-12"></i>
                </button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
    <div class="main-container">
        <!--        --><?php //include "../public_flow/flow_show_tit.php";?>
        <div class="export-print">
            <!--            --><?php //include "../public_flow/flow_show_info.php";?>
            <div class="table-box">
                <div class="title">基本信息</div>
                <table class="layui-table table-detail">
                    <tbody>
                    <tr><td>项目名称</td><td id="enginname" class="colorlan" colspan="3"></td></tr>
                    <tr><td>预算金额(元)</td><td id="money"></td><td>剩余金额(元)</td><td id="shengfee"></td></tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="layui-row layui-col-space15" style="margin-top: 15px">
            <div class="layui-col-md12">
                <div class="table-box">
                    <div class="title-list">
                        预算明细
                        <span class="title-icon"><i class="layui-icon layui-icon-down"></i></span>
                    </div>
                    <div class="layui-col-md12" id="table_list">
                        <div id="shoulist" key="0" style="margin: 15px 0 0 15px;cursor: pointer;float: left;margin-right: 20px">全部收起</div>
                        <button id="yuwainum" type="button" class="layui-btn layui-btn-sm btn-dark marginr5 layui-hide" style="margin-top: 10px;float: right">预算外数据</button>
                        <div style="clear: both"></div>



                        <div class="layui-card-body">
                            <table id="datalist" lay-filter="datalist"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="file-show" id="upload_files"><?php include '../public/upinfo_show.php' ?></div>
        <div class="opt-browse"><?php include '../public_flow/flow_show_shenlog.php'?></div>
        <div class="opt-browse"><?php include '../public_flow/flow_show_talk.php'?></div>
        <div class="opt-browse"><?php include '../public/opt_browse.php'?></div>
    </div>
    <div class="line"></div>
</div>
<script>
    var param_id = getQueryVariable('id') || 0;


    var mytable;
    layui.use(['form', 'layer','element','dropdown',"tree", "laytp",'laypage','table','form','soulTable'], function () {
        var form = layui.form,element = layui.element;
        var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, soulTable = layui.soulTable,treeTable=layui.treeTable;

        facade.ajax({url: ask_engin_budget_zhi_show, data:{id: param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                var butauth = res.data.butauth;
                var engininfo = res.data.engininfo;

                $("#enginname").text(engininfo.name).click(function () {
                    openPage('../engin/show.php?id='+engininfo.id);
                });

                $("#money").text(data.money);
                $("#shengfee").text(data.shengfee);
                if(data.yuwainum > 0){
                    $("#yuwainum").html('预算外数据（'+data.yuwainum+'）').removeClass('layui-hide').click(function () {
                        var isauth = false;
                        for (var key in butauth){
                            if(butauth[key].butname == 'editout'){
                                isauth = true;
                            }
                        }

                        if(isauth){
                            openPage('yuwai.php?close=1&id='+data.id);
                        }else{
                            facade.error("对不起，您没有操作权限");return false;
                        }
                    });
                }


                mytable = treeTable.render({
                    elem: "#datalist",
                    id: "datalist",
                    title: "成本科目",
                    data:res.data.list,
                    where: {pid:1},
                    page: true,
                    method: TabInit.method,
                    request: TabInit.request,
                    response: TabInit.response
                    , tree: {
                        iconIndex: 0        // 折叠图标显示在第几列
                        , arrowType: 'arrow2'   // 自定义箭头风格
                        , getIcon: function (d) {  // 自定义图标
                            // d是当前行的数据
                            if (d.children && d.children.length > 0) {  // 判断是否有子集
                                return '<i class="laytp-tree-icon laytp-tree-icon-folder"></i>';
                            } else {
                                return '<i class="laytp-tree-icon laytp-tree-icon-file"></i>';
                            }
                        }
                    }
                    , cols: [[
                        {field: 'name', title: '成本科目',width:300,templet: function(d){
                                if(d.name == '#.合同项'){
                                    return '<span class="colorlan">'+d.name+'</span>';
                                }else{
                                    return d.name;
                                }
                            }}
                        ,{field:'subid_name',title:'名称及规格'}
                        ,{field: 'unit', title: '单位'}
                        ,{field: 'num', title: '数量'}
                        ,{field: 'price', title: '单价(元)'}
                        ,{field: 'money', title: '金额(元)'}
                        ,{field: 'zhannum', title: '占用数量'}
                        ,{field: 'zhanmoney', title: '占用金额(元)'}
                        ,{field:'shengnum',title:'剩余数量',templet: function(d){
                                if(d.shengnum == '/'){
                                    return d.shengnum;
                                }else{
                                    if(d.shengnum < 0){
                                        return '<span class="colorhong">'+d.shengnum+'</span>';
                                    }else{
                                        return d.shengnum;
                                    }
                                }
                            }}
                        ,{field:'shengmoney',title:'剩余金额(元)',templet: function(d){
                                if(d.shengmoney == '/'){
                                    return d.shengmoney;
                                }else{
                                    if(d.shengmoney < 0){
                                        return '<span class="colorhong">'+d.shengmoney+'</span>';
                                    }else{
                                        return d.shengmoney;
                                    }
                                }
                            }}
                        ,{field: 'explain', title: '备注'}
                    ]]
                    , done: function (res) {
                        setTimeout(function () {
                            mytable.expandAll();
                            mytable.expandAll();
                            mytable.expandAll();
                            mytable.expandAll();
                            mytable.expandAll();
                            mytable.expandAll();
                            mytable.expandAll();
                            mytable.expandAll();
                            mytable.expandAll();
                            mytable.expandAll();
                        },100)
                    }
                });


                $("#shoulist").click(function () {
                    if($(this).attr('key') > 0){
                        mytable.expandAll();
                        $(this).attr('key', 0).text('全部收起');
                    }else{
                        mytable.foldAll();
                        $(this).attr('key', 1).text('全部展开');
                    }

                });

                public_flow_show_display(res.data.billinfo);
                public_upload_show_file('upload_files', res.data.files);
                render_from();
            }
        });


        public_get_readsandlog('engin_budget', param_id);
    });







</script>
</body>
</html>
